// JavaScript Document
function emailInput(){
	var myemail = document.getElementById("myemail");
	myemail.value = "";
	myemail.style.color = "#000";
}
function emailWrong(){
	var emailWrong = document.getElementById("emailWrong");
	var email = document.getElementById("myemail").value;
	var re = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])/;
	var objExp=new RegExp(re); 
	if(!objExp.test(email)){
		emailWrong.style.visibility = 'visible';
		return false;
	}
	else{
		emailWrong.style.visibility = 'hidden';	
		return true;
	}		
}
function nameWrong(){
	var nameWrong = document.getElementById("nameWrong");
	var name = document.getElementById("name").value;
	
	if(name == ""||name.length>10||name.length<2){
		nameWrong.style.visibility = "visible";
		nameWrong.innerHTML = "长度不正确只可2至10位"
		nameWrong.style.color = "red";
		return false;
	}
	//实例化异步通行对象
	if (window.XMLHttpRequest){
		req = new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	if(req){
		req.open("GET","/networkforum/main/register_checkName.do?userName="+name, true);
		req.onreadystatechange = userComplete;
		req.send(null);
	}
}
function userComplete(){
	if (req.readyState == 4){
		if (req.status == 200){
			var valu = req.responseText;
			var nameWrong = document.getElementById("nameWrong");
			
			nameWrong.innerHTML = valu; 
			nameWrong.style.visibility = "visible";
			if(valu == "恭喜你，该名称可以使用"){
				nameWrong.style.color = "green";
				document.getElementById("sub").disabled = false;
			}
			else {
				nameWrong.style.color = "red";
				document.getElementById("sub").disabled = true;
			}
		}
	}
}
function passwordWrong(){
	var passwordWrong = document.getElementById("passwordWrong");
	var password1 = document.getElementById("password1").value;
	var password2 = document.getElementById("password2").value;
	if(password1.length<6||password1.length>16){
		passwordWrong.innerHTML = "密码长度6-16位";
		passwordWrong.style.visibility = "visible";
		return false;
	}
	if(password1 != password2){
		passwordWrong.innerHTML = "两次密码不一至 ";
		passwordWrong.style.visibility = "visible";
		return false;
	}
	else{
		passwordWrong.style.visibility = "hidden";
	}
	return true;
}
function register(){
	if(!emailWrong()){
		return false;
	}
	if(!passwordWrong()){
		return false;
	}
	return true;
}